Highlighting
TextEdit highlights a group of characters that is contiguous in memory (backing-store order). However, the highlighted text may appear
discontinuous on the display line if the selection contains mixed- directional
text, as shown in the next figure. This is because TextEdit draws characters in display order, which may be different from backing-store order. The caret
positions are also determined similarly. The display order is determined by the
ordering of the characters within a direction run and the ordering of direction
runs in the primary line direction.
Character offsets are byte offsets of the characters in the text buffer, and the
values of character offsets correspond to the backing-store order of
characters.
Discontinuous highlighting display
A caret position is a location on the screen corresponding to a leading or
trailing edge of a displayed character. In mixed- directional text, one character
offset may correspond to two caret positions, and one caret position may
correspond to two character offsets.
These ambiguous cases occur at direction boundaries because the character
offset is associated with two different characters-the one before and the one
after the offset. When these characters are not adjacent in the display, two
caret positions result. The primary caret position is the screen location
associated with the character that has the same direction as the primary line
direction. The secondary caret position is the screen location associated with
the character that has a different direction from the primary line direction.
TextEdit uses only the primary caret positions in determining which characters are highlighted.
In the previous figure and in the next figure, you can see how the primary and
secondary caret positions differ at direction boundaries 4 and 12. In the next
figure, you can see the relationship between the character offsets and the
primary and secondary caret positions. The next figure illustrates how
TextEdit uses primary caret positions to define highlighting boundaries for the highlighting of characters 2, 3, 4, and 5. The shaded regions indicate the
highlighted characters. To highlight characters 2 and 3, TextEdit inverts the entire area between primary caret positions 2 and 4. To highlight characters 4
and 5, it inverts the entire area between primary caret positions 12 and 6.
Highlighting mixed- directional text.
When a non-Roman script system is installed, TextEdit calls the (with a direction value of smHilite) to ascertain which characters should be
highlighted.
TextEdit routines that specifically need highlighting of a selection or that produce highlighting as a result of their functions include TEActivate,